<!-- Student_selectLocationAddress.html -->
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" >
		<title>选择地址页</title>
		<link rel="stylesheet" type="text/css" href="../../css/weui.min.css"/>
		<link rel="stylesheet" type="text/css" href="../../css/CFNetPP_Base.css">
		<style type="text/css">
			.weui_cells_title{
				line-height: 30px;
				margin: 0;
			}
			.location-title{
				font-size: 14px;
				color: #333;
			}
			.location-sub-title{
				font-size: 12px;
				color: #999;
				margin-top: 4px;
			}
		</style>
	</head>
	<body>
		<div class="base_style_color " id='BarAppearance' style="height: 22px;width: 100%"></div>
		<div class="base_navigation_bar base_style_color base_navigation_item_bar">
			<a class="base_left_item" href="#" onclick="backClick()"> <img class="base_back_icon" src="../../image/icon_jiantou.png" alt=""> </a>
			<span>当前位置</span>
			<a class="base_right_item base_hide_item"> </a>
		</div>
		<div class="base_content_div">
			<div class="weui_cells_title">请选择位置</div>
		    <div id="location_list" class="weui_cells weui_cells_radio">
	        	<!-- <label class="weui_cell weui_check_label" for="x11">
		          	<div class="weui_cell_bd weui_cell_primary">
		            	<p class="location-title">东八里庄小学</p>
		            	<p class="location-sub-title">八里庄东里12号</p>
		          	</div>
		          	<div class="weui_cell_ft">
		            	<input type="radio" class="weui_check" name="radio1" id="x11" checked="checked">
		            	<span class="weui_icon_checked"></span>
		          	</div>
	        	</label> -->
		    </div>
		</div>
	</body>
	<script type="text/javascript" src="../../script/api.js"></script>
	<script type="text/javascript" src="../../script/jquery.min.js"></script>
	<script type="text/javascript">
		apiready = function(){
		    getLocation(function(ret, err){
		    	if (ret.status == true) {
		    		var addressArr = ret.poiList;
		    		if (addressArr != null && addressArr.constructor == Array && addressArr.length > 0) {
		    			var htmlString = '';
		    			for (var i = 0; i < addressArr.length; i++) {
		    				var addressData = addressArr[i];
		    				htmlString += htmlStringWithData(addressData, i);
		    			}
		    			$('#location_list').html(htmlString);
		    			addCellClick();
		    		}else{
		    			api.toast({
			    		    msg: '获取位置信息失败'
			    		});
		    		}
		    	}else{
		    		api.toast({
		    		    msg: '获取位置信息失败'
		    		});
		    	}
		    });
		}
		//获取百度地图!
		function getLocation(callback) {
			var bMap = api.require('bMap');
			bMap.getLocation({
				accuracy : '100',
				autoStop : true,
				filter : 1
			}, function(ret, err) {
				if (ret.status) {
					var lon = parseFloat(ret.lon);
					var lat = parseFloat(ret.lat);
					nowLat = lat;
					nowLon = lon;
					bMap.getNameFromCoords({
						lon : lon,
						lat : lat
					}, function(ret, err) {
						callback(ret, err);
					});
				} else {
					callback('', 'err');
				}
			});
		}  
		function htmlStringWithData(data, index){
			var checkedStatus = '';
			if (index == api.pageParam.index) {
				checkedStatus = 'checked="checked"';
			}
			return '<label index="'+index+'" address="'+data.city+'·'+data.name+'" class="weui_cell weui_check_label location_cell" for="'+index+'">'+
		          	'<div class="weui_cell_bd weui_cell_primary">'+
		            	'<p class="location-title">'+data.name+'</p>'+
		            	'<p class="location-sub-title">'+data.address+'</p>'+
		          	'</div>'+
		          	'<div class="weui_cell_ft">'+
		            	'<input type="radio" class="weui_check" name="radio1" id="'+index+'" '+checkedStatus+'>'+
		            	'<span class="weui_icon_checked"></span>'+
		          	'</div>'+
	        	'</label>';
		}
		function addCellClick(){
			$('.location_cell').unbind('click');
			$('.location_cell').click(function(){
				var index = $(this).attr('index');
				var address = $(this).attr('address');
				api.sendEvent({
				    name: 'selectLocationNotifi',
				    extra: {
				        index: index, 
				        address: address
				    }
				});
				backClick();
			});
		}
		function backClick(){
			api.closeWin();
		}
	</script>
</html>